# -*- coding: utf-8 -*-
# ###########################################################################
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

import time
from osv import osv, fields
from tools.translate import _
from tools import config
import base64
import csv
import cStringIO
import tools


class account_invoice(osv.osv):
    _inherit = 'account.invoice'

    def _date_ref_get_fnc(self, cr, uid, ids, name, args, context=None):
        res = {}
        for invoice in self.browse(cr, uid, ids, context=context):
            res[invoice.id] = {
                'payment_ref': '',
                'payment_date': False,
            }
            if invoice.payment_ids:
                res[invoice.id] = {
                    'payment_ref': invoice.payment_ids[0].ref,
                    'payment_date': invoice.payment_ids[0].date,
                }
        return res

    _columns = {
        'payment_ref': fields.function(_date_ref_get_fnc, method=True, type="char", string='Nº Recibo', multi='all'),
        'payment_date': fields.function(_date_ref_get_fnc, method=True, type="date", string='Fecha de Pago',
                                        multi='all'),
    }


account_invoice()
